/**
 * Created by Administrator on 2017/2/16.
 */
import java.sql.*;
public class Jdbc {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet =null;

        try{
           Driver driver =new com.mysql.jdbc.Driver();
            DriverManager.registerDriver(driver);

            String url= "jdbc:mysql://localhost:3306/tabletest?characterEncoding=utf8";
            String user="root";
            String password="root";
            connection=DriverManager.getConnection(url,user,password);
            statement= connection.createStatement();
            String sql="select * from users";
            resultSet =statement.executeQuery(sql);

            while (resultSet.next()){
                String name=resultSet.getString(2);
                String pass=resultSet.getString(3);

                System.out.println(name +"; "+ pass);
            }
        } catch (SQLException e) {
            System.out.println("数据库连接失败");
        }finally {
            if(resultSet != null){
                try {
                    resultSet.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
